package com.example.Lezedata.ui.activity.common;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.Lezedata.R;

public class GBCell extends FrameLayout {

    public Drawable leftDrawable;
    public String string;
    private TextView textView;
    public Drawable rightDrawable;

    public static GBCell newInstance(Context context) {
        GBCell cell = (GBCell)LayoutInflater.from(context).inflate(R.layout.activity_prodetail_history,null,false);
        return cell;
    }

    public GBCell(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        textView = findViewWithTag("textView");
        Drawable[] drawables = textView.getCompoundDrawables();
        leftDrawable = drawables[0];
        rightDrawable = drawables[2];
    }

    public void setLeftDrawable(Drawable drawable) {
        this.leftDrawable = drawable;
        refreshDrawable();
    }

    public void setRightDrawable(Drawable drawable) {
        this.rightDrawable = drawable;
        refreshDrawable();
    }

    void refreshDrawable(){
        textView.setCompoundDrawablesWithIntrinsicBounds(leftDrawable,null,rightDrawable,null);
    }

    public void setString(String string) {
        this.string = string;
        textView.setText(string);
    }
}
